/**
 * 前往书籍详情
 * @param {Int} id [书籍id]
 * @param {Int} price [书籍价格]
 * @param {WebView} page [当前窗口]
 * @author Qasim <15750783791@163.com>
 * @version 2011/11/18 1.0
 */
function bookDetails(id , price , page){
	if(parseInt(price) == 0){
		var parameter = {aid : id ,page : page };
		goUrl('book-detail.html' , 'book_detail' , parameter)
	}else{
		var parameter = {aid : id ,page : page};
    	goUrl('book-detail-needbuy.html' , 'book_detail_needbuy' , parameter)
	}
	
	setTimeout(function(){
		mui.fire(plus.webview.getWebviewById(plus.storage.getItem('index_page')) , 'update_hits' , {aid : id})
	} , 1000);
}



/**
 * 阅读
 * @param {Int} id [书籍id]
 * @param {Boolean} isbuy [是否购买]
 * @param {webview} page [当前页面]
 * @param {String} book_name [书名]
 * @param {String} pattern 免费/收费
 */
function read(id , isbuy , page , book_name , pattern){ 
	var ordinal = plus.storage.getItem('chapter'+id);
	if(!ordinal){
		ordinal = 1;
	}
	$.ajax({  
		type : 'post',
		url : apiRoot + '/Home/Chapter/chapterDetails/',
		data : { 
			id : id,
			ordinal : ordinal
		},
		beforeSend : function(){
			plus.nativeUI.showWaiting();
		},
		complete: function(){
			plus.nativeUI.closeWaiting();
		},
		dataType:'json',
		success : function(data){  
			if(data.single){
				plus.storage.setItem('chapter'+id , data.single.ordinal+'');
				var parameter = {aid:id , page:page , isbuy : isbuy , name:book_name,pattern:pattern,chapter:data};
				goUrl('read-books.html' , 'read_books' , parameter);
			}else{
				toast('该书籍还没有上传章节哦 ')
			}
		},
		error : function(e){ 
			errorPrompt(e); 
		}
	})
}


